#!/bin/sh

HDR_DIR=headers
XML_DIR=xml

mkdir -p ${HDR_DIR}
mkdir -p ${XML_DIR}

echo "-- generating header files --"

rm -rf ${HDR_DIR}
mkdir -p ${HDR_DIR}/aversive/parts

cd ${XML_DIR}
for i in *.xml ; do
    echo $i
    ../gen_regs.py $i > ../${HDR_DIR}/aversive/parts/${i%.xml}.h
done
cd -

cd ${HDR_DIR}/aversive/parts

EL=
cat <<EOF > ../parts.h
/*  
 *  Copyright Droids Corporation, Microb Technology, Eirbot (2009)
 * 
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 *  Revision : $Id $
 *
 */

/* WARNING : this file is automatically generated by scripts.
 * You should not edit it. If you find something wrong in it,
 * write to zer0@droids-corp.org */

#ifndef _AVERSIVE_PARTS_H_
#define _AVERSIVE_PARTS_H_

EOF

for i in *.h ; do
    part=${i%.h}
    part=${part#aversive_}
    if [ "$part" = "parts" ]; then
	continue
    fi
    echo "#${EL}if defined (__AVR_${part}__)" >> ../parts.h
    echo "#include <aversive/parts/$i>" >> ../parts.h
    EL=el
done
echo "#else" >> ../parts.h
echo "#error \"This arch is not implemented yet\"" >> ../parts.h
echo "#endif" >> ../parts.h
echo >> ../parts.h
echo "#endif /* _AVERSIVE_PARTS_H_ */" >> ../parts.h
cd -

